package com.itheima.dao;


import com.itheima.domain.Permission;
import com.itheima.domain.Role;
import com.itheima.domain.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface UserInfoDao {
    /*
    * 登陆
    * */
    @Select("select * from users where username=#{username} and PASSWORD=#{password}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "PASSWORD",property = "password")
    })
    UserInfo login(@Param("username") String username, @Param("password")String password);

    /*
    * 修改密码
    * */
    @Update("update users set  PASSWORD=#{pwd} where id=#{id}")
    void updateById( @Param("id") String id, @Param("pwd") String pwd);



    @Select("select * from users where id=#{ids}")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "STATUS",property = "status"),
            @Result(column = "email",property = "email"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "username",property = "username"),
            @Result(property = "roles",javaType = List.class,column = "id",
                    many=@Many(select = "com.itheima.dao.UserInfoDao.RoleHelp"))
    })
    UserInfo ShowAll(String ids);

    @Select("select * from role where id in (select roleId from users_role where userId=#{id})")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "roleName",property = "roleName"),
            @Result(column = "roleDesc",property = "roleDesc"),
            @Result(property = "permissions",javaType = List.class,column = "id",
                    many=@Many(select = "com.itheima.dao.UserInfoDao.PerHelp"))
    })
    List<Role> RoleHelp(String ids);

    @Select("select * from permission where id in (select permissionId from role_permission where roleId=#{id})")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "permissionName",property = "permissionName"),
            @Result(column = "url",property = "url")
    })
    List<Permission> PerHelp(String ids);
}
